// First example of jQuery and key input handling
//  note we don't have multi-key input here.



// code inside $(function(){} will run after the DOM is loaded and ready

// let's experiment
//$(function(){
//    $("#paddleB").css("top", "20px");
//    $("#paddleA").css("top", "60px");
//});


//NB.   paddleA is the LHS one
//      paddleB is the RHS
//
var KEY = {
    UP: 38,
    DOWN: 40,
    W: 87,
    S: 83
}

$(function() {
    // listen for key events
    $(document).keydown(function(ev) {
        switch(ev.which) {
            case KEY.UP:  // arrow-up
                // get pad b's current -top- value
                var top = parseInt($('#paddleB').css('top'));
                // and move it up by 5px
                $('#paddleB').css('top', top-5);
                break;

            case KEY.DOWN: // arrow-down
                var top = parseInt($('#paddleB').css('top'));
                // move it down by 5px
                $('#paddleB').css('top', top+5);
                break;

            case KEY.W:
                var top = parseInt($('#paddleA').css('top'));
                // move A up by 5px
                $('#paddleA').css('top', top-5);
                break;

            case KEY.S:
                var top = parseInt($('#paddleA').css('top'));
                // move A down by 5px
                $('#paddleA').css('top', top+5);
                break;
        }
    });
});

